<template>
  <div>
    <div class="box">
      <div>
        <p>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: 'one' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>正文</el-breadcrumb-item>
          </el-breadcrumb>
        </p>
        <div class="content">
          <h1>{{ obj.title }}</h1>
          <p>
            <span>发表于{{ obj.updateTime }}</span>
            <span>分类{{ obj.categoryName }}</span>
            <span>浏览量{{ obj.readNum }}</span>
          </p>
          <div>
            <p v-html="obj.content"></p>
          </div>
          <span v-for="item in obj.tags" :key="item.id">{{ item.name }}</span>
          <span>打完</span>
          <span>vue</span>
        </div>
      </div>
      <div>
        <div class="fen">
          <div class="prev" v-show="!prev == ''">
            <p @click="prevBtn">←上一篇</p>
            <p @click="prevBtn">{{prev}}</p>
          </div>
          <div class="next" v-show="!next == ''">
            <p @click="nextBtn">下一篇→</p>
            <p @click="nextBtn">{{next}}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      obj: {},
      prev: "",
      next: "",
      id:0,
    };
  },
  created() {
    this.id=this.$route.query.articleId;
    this.indexList();
    this.seek()
  },
  methods: {
      seek() {
      this.$emit("back", [true,false]);
    },
    // 上一页
    prevBtn(){
      let i=Number(this.id);
      i+=1;
      console.log(i,'i的值')
      this.id=i;
      console.log(this.id,'id')
      this.indexList();
    },
    nextBtn(){
      let i=Number(this.id);
      i-=1;
      console.log(i,'i的值')
      this.id=i;
      console.log(this.id,'id')
      this.indexList();
    },
    //显示内容
    indexList() {
      this.$axios
        .post("http://47.104.167.34:9110/api/article/detail", {
          articleId: this.id,
        })
        .then((res) => {
          this.obj = res.data.data;
          console.log(res, "附页");
          if (res.data.data.nextArticle == null) {
            this.next = '';
          } else {
            this.next = res.data.data.nextArticle.title;

          }
          if (res.data.data.preArticle == null) {
            console.log("1空");
            this.prev='';
          } else {
            console.log("1有东西");
            this.prev=res.data.data.preArticle.title;
          }

        });
    },
  }, //methods结束
};
</script>

<style scoped>
.box {
  width: 100%;
  height: 300px;
  background-color: white;
}
.box > div:nth-child(1) {
  padding: 10px;
  border-bottom: 1px solid black;
}
.box > div:nth-child(2) {
  padding: 0 10px;
  margin-top: 10px;
}
.box > div > p {
  height: 50px;
  display: flex;
  align-items: center;
  /* background-color: blue; */
}
.content > p > span {
  margin-right: 30px;
}
.content > div {
  margin: 10px 0;
}
.content > span {
  display: inline-block;
  background-color: bisque;
  margin-right: 10px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  padding: 0px 5px;
  border-radius: 5px;
}
.fen {
  width: 100%;
  text-align: center;
}
.fen > div {
  /* width: 80px; */
  height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.prev{
  float: left;
}
.next{
  float: right;
}
.fen > div > p {
  cursor: pointer;
}
</style>